package com.personal.website.lottery.table

import java.util
import scala.collection.JavaConverters._

/**
 * Created by Gavin on 2015/12/14.
 */
class FourPart012Table (issue: Int,redBalls: Seq[Int], blueBall: Int) extends Table(issue,redBalls,blueBall){
  override def createRecord(): Seq[Int] = FourPart012Table.ALL_EXISTS_BALLS.map(ball => if(redBalls.contains(ball)) ball else DEFAULT_NON_EXISTS_VALUE )
  override def toString: String = Seq(Seq(issue),Seq(createSum()),createRecord()).flatten.mkString(";")
}

object FourPart012Table{
  def apply(issue: Int,redBalls: Seq[Int], blueBall: Int) = new FourPart012Table(issue,redBalls,blueBall)
  def apply(issue: Int,allBalls: Seq[Int]) = new FourPart012Table(issue,allBalls.init,allBalls.last)
  def newInstance(issue: Integer,redBalls: util.List[Integer],blueBall: Integer) = new FourPart012Table(issue.toInt, redBalls.asScala.map(_.toInt),blueBall.toInt)

  val ALL_EXISTS_BALLS = Seq((1 to 8),(9 to 16),Seq(17),(18 to 25),(26 to 33)).map(sortWith012).flatten

  def sortWith012(seq: Seq[Int]) = seq.filter(_ % 3 == 0) ++ seq.filter(_ % 3 == 1) ++ seq.filter(_ % 3 == 2)

  val headString = Seq("issue","sum",ALL_EXISTS_BALLS).mkString("|")
}